package com.fenghongzhang.kotlin1903.mvp.view

import androidx.recyclerview.widget.LinearLayoutManager
import com.fenghongzhang.kotlin1903.mvp.adapter.FoodAdapter
import com.fenghongzhang.kotlin1903.R
import com.fenghongzhang.kotlin1903.model.Data
import com.fenghongzhang.kotlin1903.mvp.contract.FoodContract
import com.fenghongzhang.kotlin1903.mvp.model.FoodModel
import com.fenghongzhang.kotlin1903.mvp.presenter.FoodPresenter
import kotlinx.android.synthetic.main.activity_food.*

class FoodActivity : BaseActivity<FoodPresenter>(),FoodContract.IFoodView{

    lateinit var list :MutableList<Data>
    lateinit var foodAdapter: FoodAdapter
    override fun bindLayout(): Int {
        return R.layout.activity_food
    }

    override fun initView() {
        list = mutableListOf()
        food_rv.layoutManager = LinearLayoutManager(this)
        foodAdapter = FoodAdapter(this,list)
        food_rv.adapter = foodAdapter
    }

    override fun initData() {
        p = FoodPresenter(this,FoodModel())
        p.getFood()
    }

    override fun initAdapter(food: MutableList<Data>) {
        foodAdapter.data.clear()
        foodAdapter.data.addAll(food)
        foodAdapter.notifyDataSetChanged()
    }
}
